package cannot.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cannot.mapper.PraiseMapper;
import cannot.pojo.Praise;
import cannot.pojo.PraiseExample;
import cannot.pojo.Remark;
import cannot.pojo.RemarkExample;
import cannot.service.PraiseService;

@Service
public class PraiseServiceImpl implements PraiseService {
	
	@Autowired
	PraiseMapper PraiseMapper;

	@Override
	public void insertPraise(Praise praise) {
		PraiseMapper.insert(praise);
	}

	@Override
	public void deletePraise(Integer id) {
		PraiseMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Praise selectByTvAndUid(Integer tvId, Long uId) {
		PraiseExample example = new PraiseExample();
		example.createCriteria().andTv_idEqualTo(tvId).andUidEqualTo(uId);
		List<Praise> praises = PraiseMapper.selectByExample(example);
		if(praises.size()>0){
			return praises.get(0);
		}
		return null;
	}

	@Override
	public Integer selectCountById(Integer id) {
		return PraiseMapper.selectCountById(id);
	}

	@Override
	public void deleteByTvId(Integer id) {
		PraiseExample example = new PraiseExample();
		example.createCriteria().andTv_idEqualTo(id);
		List<Praise> praises = PraiseMapper.selectByExample(example);
		for(Praise praise:praises){
			PraiseMapper.deleteByPrimaryKey(praise.getId());
		}
	}

}
